package com.itgaohe.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itgaohe.dao.entity.Shop;
import com.itgaohe.dao.mapper.ShopDao;
import com.itgaohe.service.ShopService;
import com.itgaohe.utils.Result;
import io.lettuce.core.models.role.RedisSentinelInstance;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shop")
@Tag(name = "商店管理", description = "用户相关操作")
public class ShopController {
    @Autowired
    private ShopService  shopService;
    @Autowired
    private ShopDao shopDao;

    /**
     * 根据商铺id查询商铺详情
     * @param shopId
     * @return
     */
    @Operation(summary = "根据商铺id查询商铺详情")
    @GetMapping("/{shopId}")
    public Result getShopInfo(@PathVariable("shopId") String shopId) {
        Long id = Long.parseLong(shopId);
        Shop shop = shopService.getShopById(id);
        return Result.ok(shop);
    }

    /**
     * 根据类型ID查询商铺（游标分页）
     */
    @Operation(summary = "根据类型ID查询商铺（游标分页）")
    @GetMapping("/of/type")
    public Result queryShopByType(
            @RequestParam("typeId") Long typeId,
            @RequestParam(value = "cursor", defaultValue = "1") Long cursor) {
        return shopService.queryShopByType(typeId, cursor);
    }

    /**
     * 查询所有店铺
     * @param cursor 游标
     * @return
     */
    @Operation(summary = "查询所有店铺")
    @GetMapping("/list")
    public Result searchAllShop(@RequestParam(value = "cursor", defaultValue = "1") Long cursor) {
        return shopService.queryAllShops(cursor);

    }

    /**
     * 查询商铺列表
     */
    @Operation(summary = "查询商铺列表")
    @GetMapping("/shops")
    public Result searchShops() {
        return Result.ok(shopService.list());
    }

}
